package org.edu.modules.center.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.common.system.base.controller.BaseController;
import org.edu.common.system.vo.LoginUser;
import org.edu.common.util.TimeStampUtil;
import org.edu.modules.center.entity.VeAddonsStar;
import org.edu.modules.center.entity.VeAddonsStarDetail;
import org.edu.modules.center.service.IVeAddonsStarDetailService;
import org.edu.modules.center.vo.VeAddonsStarDetailVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags={"星级评价明细表"})
@RestController
@RequestMapping({"/center/veAddonsStarDetail"})
public class VeAddonsStarDetailController
        extends BaseController<VeAddonsStarDetail, IVeAddonsStarDetailService>
{
    private static final Logger log = LoggerFactory.getLogger(VeAddonsStarDetailController.class);
    @Autowired
    private IVeAddonsStarDetailService veAddonsStarDetailService;

    @AutoLog("星级评价明细表-通过id查询")
    @ApiOperation(value="通过id查询", notes="星级评价明细表-通过id查询")
    @PostMapping({"/queryById"})
    public Result<?> queryById(@RequestParam(name="id", required=true) String id)
    {
        VeAddonsStarDetail veAddonsStarDetail = (VeAddonsStarDetail)this.veAddonsStarDetailService.getById(id);
        if (veAddonsStarDetail == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(veAddonsStarDetail);
    }

    @AutoLog("星级评价明细表-新增信息")
    @ApiOperation(value="新增信息", notes="星级评价明细表-新增信息")
    @PostMapping({"/add"})
    public Result<?> add(@RequestBody VeAddonsStarDetailVo veAddonsStarDetailVo)
    {
        int userId = 0;int objectId = 0;
        int starId = 0;
        starId = veAddonsStarDetailVo.getTcid().intValue();
        String ip = new String("abc");
        LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
        if (sysUser != null) {
            userId = Integer.valueOf(sysUser.getUserId());
        }
        int date = TimeStampUtil.getNowSecondStamp();
        VeAddonsStarDetail veAddonsStarDetail = new VeAddonsStarDetail();
        BeanUtils.copyProperties(veAddonsStarDetailVo, veAddonsStarDetail);
        veAddonsStarDetail.setAddtime(Integer.valueOf(date));
        veAddonsStarDetail.setUserid(Integer.valueOf(userId));
        veAddonsStarDetail.setStarid(Integer.valueOf(starId));
        veAddonsStarDetail.setIp(ip);

        VeAddonsStar veAddonsStar = new VeAddonsStar();
        String model = "teach";
        veAddonsStar.setObjectid(veAddonsStarDetailVo.getTcid());
        veAddonsStar.setModel(model);
        this.veAddonsStarDetailService.save(veAddonsStarDetail);
        return Result.OK("添加成功！");
    }

    @AutoLog("星级评价明细表-修改信息")
    @ApiOperation(value="修改信息", notes="星级评价明细表-修改信息")
    @PostMapping({"/edit"})
    public Result<?> edit(@RequestBody VeAddonsStarDetail veAddonsStarDetail)
    {
        this.veAddonsStarDetailService.updateById(veAddonsStarDetail);
        return Result.OK("编辑成功!");
    }

    @AutoLog("星级评价明细表-通过id删除")
    @ApiOperation(value="通过id删除", notes="星级评价明细表-通过id删除")
    @PostMapping({"/delete"})
    public Result<?> delete(@RequestParam(name="id", required=true) String id)
    {
        this.veAddonsStarDetailService.removeById(id);
        return Result.OK("删除成功!");
    }

    @AutoLog("星级评价明细表-批量删除")
    @ApiOperation(value="批量删除", notes="星级评价明细表-批量删除")
    @PostMapping({"/deleteBatch"})
    public Result<?> deleteBatch(@RequestParam(name="ids", required=true) String ids)
    {
        this.veAddonsStarDetailService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }
}
